#include <bits/stdc++.h>

using namespace std;

using ll = long long;

// 笛卡尔树
// 左斜建树

int n;

int pi[10000005];

int top;
int sta[10000005];

int lt[10000005];
int rt[10000005];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        int x;
        scanf("%d", &x);
        pi[i] = x;
    }

    for (int i = 1; i <= n; i++)
    {
        int cur = top;
        while (cur && pi[sta[cur]] > pi[i])
            cur--;
        if (cur)
            rt[sta[cur]] = i;
        if (cur < top)
            lt[i] = sta[cur + 1];
        sta[++cur] = i;
        top = cur;
    }

    return 0;
}